package com.example.boot1.util;

import java.security.SecureRandom;

public class StringHelp {

    public static String generateRandomString(int length) {
        String characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        StringBuilder randomString = new StringBuilder(length);
        SecureRandom secureRandom = new SecureRandom();
        for (int i = 0; i < length; i++) {
            int randomIndex = secureRandom.nextInt(characters.length());
            randomString.append(characters.charAt(randomIndex));
        }
        return randomString.toString();
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            String s = generateRandomString(10);
            System.out.println("随机10个字符=>"+s);

        }
    }

}
